package com.play.ballen.pack.adapter

import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.play.ballen.R
import com.play.ballen.pack.entity.PackBallInfo
import com.play.ballen.pack.ui.PackFragment
import com.yuven.appframework.util.imageloader.ImageUtil
import com.yuven.baselib.utils.ResourceUtil

class PackBallAdapter(data: MutableList<PackBallInfo>) :
    BaseQuickAdapter<PackBallInfo, BaseViewHolder>(R.layout.item_pack_ball, data) {

    var type = ""

    override fun convert(holder: BaseViewHolder, item: PackBallInfo) {

        val imgBall = holder.getView<ImageView>(R.id.imgBall)
        val imgStatus = holder.getView<ImageView>(R.id.imgStatus)
        val tvPropertyNo = holder.getView<TextView>(R.id.tvPropertyNo)
        val tvPropertyLevel = holder.getView<TextView>(R.id.tvPropertyLevel)
        val tvPropertySport = holder.getView<TextView>(R.id.tvPropertySport)
        val tvPropertyDate = holder.getView<TextView>(R.id.tvPropertyDate)
        val tvPropertyPlayCount = holder.getView<TextView>(R.id.tvPropertyPlayCount)
        val tvPropertyStock = holder.getView<TextView>(R.id.tvPropertyStock)
        val tvPropertyPrice = holder.getView<TextView>(R.id.tvPropertyPrice)
        val btn = holder.getView<Button>(R.id.btn)

        item.run {
            ImageUtil.instance.loadImage(0, 0, pic, imgBall)

            tvPropertyNo.text = "Lv"+name
            tvPropertyLevel.text =   ResourceUtil.getString(R.string.home_property_no_text, no)
            tvPropertyPlayCount.text =
                ResourceUtil.getString(R.string.home_property_play_count_text, task_count)
            tvPropertyStock.text = num
            tvPropertyDate.text = if (no != "0") {
                ResourceUtil.getString(R.string.home_property_date_forever)
            } else {
                ResourceUtil.getString(R.string.twenty_end)
            }

            tvPropertySport.text = "$percent%"
            tvPropertyPrice.text = ResourceUtil.getString(R.string.home_property_price_text, price)

            when (type) {
                PackFragment.TYPE_PACK_LAPSED -> {
                    imgStatus.visibility = View.VISIBLE
                    imgStatus.setImageResource(R.mipmap.ic_pack_lapsed)

                    btn.setBackgroundResource(R.drawable.layer_grey_shadow_button)
                    btn.text = ResourceUtil.getString(R.string.pack_tab_lapsed)
                }

                PackFragment.TYPE_PACK_DESTROY -> {
                    imgStatus.visibility = View.VISIBLE
                    imgStatus.setImageResource(R.mipmap.ic_pack_expired)

                    btn.setBackgroundResource(R.drawable.layer_grey_shadow_button)
                    btn.text = ResourceUtil.getString(R.string.pack_tab_destory)
                }

                PackFragment.TYPE_PACK_OWNER -> {
                    imgStatus.visibility = View.GONE

//                    btn.setBackgroundResource(R.drawable.ripple_selector_common_button)
                    btn.text = ResourceUtil.getString(R.string.pack_btn_sale)
                }

                PackFragment.TYPE_PACK_SALE -> {
                    imgStatus.visibility = View.GONE
                    btn.setBackgroundResource(R.drawable.layer_red_shadow_button)
                    btn.text = ResourceUtil.getString(R.string.pack_btn_sale_cancel)
                }
            }
        }
    }

}